import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import local_set from '@dfeidao/atom-web/local/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
// import whoami from '@dfeidao/atom-web/msg/whoami';
import storage_get from '@dfeidao/atom-web/storage/get';
import _show from '@dfeidao/atom-web/ui/show';
import P01 from './P01';
import P02 from './P02';

// 修改弹窗显示
export default async function a001(fd: IFeidaoAiBrowserComponent, args: { formid: string, client_type: string }) {
	local_set(fd, 'client_type', args.client_type);
	const prid = storage_get('productid');

	const res = await nodejs('function-definition/zj-000004/s001', { formid: args.formid, productid: prid });
	const res1 = await nodejs<{ dataArray: Array<{ group_number: string }> }>('function-definition/zj-000001/s003', { filter: { productid: prid, client_type: args.client_type } });
	render(fd, res1, P02, 'P02', 'inner');
	fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id="formname"]').value = res[0].formname;
	fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id="package_name"]').value = res[0].package_name;
	fd.data.node.querySelector<HTMLSpanElement>('[data-feidao-id="package_path"]').innerText = res[0].package_path;
	if (!res[0].group_number) {
		fd.data.node.querySelector<HTMLSelectElement>('[data-feidao-id="group_numbers"]').value = '未分组';
	} else {
		fd.data.node.querySelector<HTMLSelectElement>('[data-feidao-id="group_numbers"]').value = res[0].group_number;
	}
	local_set(fd, 'pub_form', res[0]);
	// 功能控制点
	local_set(fd, 'formid', args.formid);
	local_set(fd, 'group_number', res[0].group_number);
	const filter = { formid: args.formid, productid: prid };
	// 查询
	const res2 = await nodejs<{ dataArray: Array<{}> }>('function-definition/zj-000004/s002', filter);
	local_set(fd, "original_data", res2.dataArray.concat()); // 原始数据
	local_set(fd, "data", res2.dataArray);
	// 渲染数据
	render(fd, res2, P01, 'P01', 'inner');
	_show(fd.data.node);
}
